package com.huawei.hwCloudJs.c;

import android.util.Log;
import com.huawei.hwCloudJs.service.jsapi.JsCoreApi$ChannelMessageReq;
import com.huawei.hwCloudJs.service.jsmsg.NativeMsg;
import org.json.JSONException;
import org.json.JSONObject;

public class a {
    public static final String a = "event_inner_error";
    public static final String b = "event_inner_ready";
    public static final String c = "ChannelMessageEvent_";
    private static final String d = "EventUtils";
    private static final String e = "javascript:hbs.handleMessage(%s);";
    private static final String f = "_event_type";
    private static final String g = "_event_type_inner";
    private static final String h = "_event_type_3rd";
    private static final String i = "_event_index";
    private static final String j = "_event_args";

    public static String a(NativeMsg nativeMsg) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put(f, h);
            String type = nativeMsg.getType();
            if ("channelMessage".equals(type) && (nativeMsg instanceof JsCoreApi$ChannelMessageReq)) {
                jSONObject.put(i, c + ((JsCoreApi$ChannelMessageReq) nativeMsg).getChannelName());
            } else {
                jSONObject.put(i, type);
            }
            jSONObject.put(j, nativeMsg.toJsonString());
        } catch (JSONException e) {
            Log.e(d, "gen3rdEvent error");
        }
        return String.format(e, new Object[]{jSONObject.toString()});
    }

    public static String a(String str, JSONObject jSONObject) {
        JSONObject jSONObject2 = new JSONObject();
        try {
            jSONObject2.put(f, g);
            jSONObject2.put(i, str);
            jSONObject2.put(j, jSONObject.toString());
        } catch (JSONException e) {
            Log.e(d, "genInnerEvent error");
        }
        return String.format(e, new Object[]{jSONObject2.toString()});
    }
}
